import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.packet.DiscoverInfo;
import org.jivesoftware.smackx.pubsub.ConfigureForm;
import org.jivesoftware.smackx.pubsub.Node;
import org.jivesoftware.smackx.pubsub.PubSubManager;

/*
 * N. Dumont, TAI Lab
 *
 * Class NodeDiscovery created on 20 mai 2011
 *
 * Copyright (c) 2009 Thales Communications
 * 160 bd de Valmy - BP82 92704 COLOMBES cedex - France
 * All rights reserved.
 *
 */

/**
 * @author tai
 * 
 */
public class NodeDiscovery {
	public static void main(String[] args) {
		NodeDiscovery d = new NodeDiscovery();
		d.start();
	}

	/**
 * 
 */
	private void start() {
		ConnectionConfiguration config = new ConnectionConfiguration("192.168.20.12", 5222);
		XMPPConnection connection = new XMPPConnection(config);
		try {
			connection.connect();
			connection.login("phidget", "phidget");
		} catch (XMPPException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		PubSubManager manager = new PubSubManager(connection);
		Node node = null;
		try {
			node = manager.getNode("diyse/devices/52861/xChanged");
		} catch (XMPPException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		if(node == null){
			System.out.println("node is null");
			return;
		}
		
		
		try {
			DiscoverInfo disco = node.discoverInfo();
			System.out.println(disco.toXML());
			
			
			ConfigureForm f = node.getNodeConfiguration();
			System.out.println("Configure form:");
			System.out.println(f);
		} catch (XMPPException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
